﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HD.Model;

namespace HDWebSite.Controllers
{
    public class TaskCompletedController : Controller
    {
        private HDDBContext db = new HDDBContext();

        //
        // GET: /TaskCompleted/

        public ActionResult Index()
        {
            var taskcompleteds = db.TaskCompleteds.Include(t => t.Task);
            return View(taskcompleteds.ToList());
        }

        //
        // GET: /TaskCompleted/Details/5

        public ActionResult Details(int id = 0)
        {
            TaskCompleted taskcompleted = db.TaskCompleteds.Find(id);
            if (taskcompleted == null)
            {
                return HttpNotFound();
            }
            return View(taskcompleted);
        }

        //
        // GET: /TaskCompleted/Create

        public ActionResult Create()
        {
            ViewBag.TaskId = new SelectList(db.Tasks, "Id", "Name");
            return View();
        }

        //
        // POST: /TaskCompleted/Create

        [HttpPost]
        public ActionResult Create(TaskCompleted taskcompleted)
        {
            if (ModelState.IsValid)
            {
                db.TaskCompleteds.Add(taskcompleted);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.TaskId = new SelectList(db.Tasks, "Id", "Name", taskcompleted.TaskId);
            return View(taskcompleted);
        }

        //
        // GET: /TaskCompleted/Edit/5

        public ActionResult Edit(int id = 0)
        {
            TaskCompleted taskcompleted = db.TaskCompleteds.Find(id);
            if (taskcompleted == null)
            {
                return HttpNotFound();
            }
            ViewBag.TaskId = new SelectList(db.Tasks, "Id", "Name", taskcompleted.TaskId);
            return View(taskcompleted);
        }

        //
        // POST: /TaskCompleted/Edit/5

        [HttpPost]
        public ActionResult Edit(TaskCompleted taskcompleted)
        {
            if (ModelState.IsValid)
            {
                db.Entry(taskcompleted).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.TaskId = new SelectList(db.Tasks, "Id", "Name", taskcompleted.TaskId);
            return View(taskcompleted);
        }

        //
        // GET: /TaskCompleted/Delete/5

        public ActionResult Delete(int id = 0)
        {
            TaskCompleted taskcompleted = db.TaskCompleteds.Find(id);
            if (taskcompleted == null)
            {
                return HttpNotFound();
            }
            return View(taskcompleted);
        }

        //
        // POST: /TaskCompleted/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            TaskCompleted taskcompleted = db.TaskCompleteds.Find(id);
            db.TaskCompleteds.Remove(taskcompleted);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}